package cn.ven.service;

import cn.ven.entity.BookType;
import cn.ven.mapper.BookTypeMapper;
import org.aspectj.lang.annotation.After;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BookTypeServiceImpl implements BookTypeService {
    @Autowired(required = false)
    BookTypeMapper bookTypeMapper;

    //添加或者修改类型
    @Override
    public void addType(BookType bookType) {
        if (bookType.getId()==0){//id==0，表示没有这个类型，就添加
            bookTypeMapper.add(bookType);
        }
        //当id!=0的时候，更新对应类型
            bookTypeMapper.update(bookType);
    }

    //查找所有的类型
    @Override
    public List<BookType> findAll() {
        return bookTypeMapper.findAll();
    }

    //根据id查找类型
    @Override
    public BookType findById(Integer id) {
        return bookTypeMapper.findById(id);
    }
}
